﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace TDTool.Utils
{
    public class Util
    {
        const string TD_REPERTORY_FOLDER_NAME = "Repertory";
        /// <summary>
        /// 所有保存的TD，都放到这个目录下。
        /// </summary>
        /// <returns></returns>
        public static string GetTDRepertoryPath()
        {
            return GetAppPath() + TD_REPERTORY_FOLDER_NAME+"\\";
        }
        public static string GetAppPath()
        {
            return AppDomain.CurrentDomain.BaseDirectory;
        }
        /// <summary>
        /// 打开路径
        /// </summary>
        /// <param name="folderPath">文件夹路径</param>
        /// <returns></returns>
        public static bool OpenFolder(string folderPath)
        {
            if (!Directory.Exists(folderPath))
                return false;
            if (System.Diagnostics.Process.Start("explorer.exe", folderPath) == null)
                return false;
            return true;
        }
        public static bool IsFileExist(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// 判断是不是数字
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool IsInt(string value)
        {
            return Regex.IsMatch(value, @"^[+-]?\d*$");
        }

        public static string GetNewTDFileName(string tdNumber, string tdName)
        {
            return "TD " + tdNumber + "__" + tdName + ".txt";
        }

        public static void CreateNewTDFile(string path, string content)
        {
            StreamWriter sw = new StreamWriter(path);
            sw.WriteLine(content);
            sw.Flush();
            sw.Close();
        }
    }
}
